package com.wutuo.school.provider.dao;

import cn.apestar.core.base.GenericMapper;
import cn.apestar.core.base.MapperAnnotation;
import com.wutuo.school.provider.domain.School;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * 校区 Dao 层
 *
 * @author lvh
 * @version 1.0
 */

@MapperAnnotation public interface BaseSchoolMapper extends GenericMapper<School, Long> {

    @Override @Delete({"delete from school", "where id = #{id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long id);

    @Override @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert({"insert into school (", "school_name,", "phone,", "logo,", "address,", "province,",
        "city,", "county,", "create_by,", "create_date,", "update_by,", "update_date,", "remarks,",
        "lat,", "lng,", "del_flag", " )values(", "#{schoolName,jdbcType=VARCHAR},",
        "#{phone,jdbcType=VARCHAR},", "#{logo,jdbcType=VARCHAR},", "#{address,jdbcType=VARCHAR},",
        "#{province,jdbcType=VARCHAR},", "#{city,jdbcType=VARCHAR},", "#{county,jdbcType=VARCHAR},",
        "#{createBy,jdbcType=BIGINT},", "#{createDate,jdbcType=DATE},",
        "#{updateBy,jdbcType=BIGINT},", "#{updateDate,jdbcType=DATE},",
        "#{remarks,jdbcType=VARCHAR},", "#{lat,jdbcType=VARCHAR},", "#{lng,jdbcType=VARCHAR},",
        "#{delFlag,jdbcType=VARCHAR})"}) int insert(School record);

    @InsertProvider(type = BaseSchoolSqlProvider.class, method = "insertSelective")
    int insertSelective(School record);

    @Override
    @Select({"select", "school_name,", "lat,", "lng,", "phone,", "logo,", "address,", "province,",
        "city,", "county,", "create_by,", "create_date,", "update_by,", "update_date,", "remarks,",
        "del_flag", "from school", "where id = #{id,jdbcType=BIGINT}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
        @Result(column = "school_name", property = "schoolName", jdbcType = JdbcType.VARCHAR),
        @Result(column = "lat", property = "lat", jdbcType = JdbcType.VARCHAR),
        @Result(column = "lng", property = "lng", jdbcType = JdbcType.VARCHAR),
        @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
        @Result(column = "logo", property = "logo", jdbcType = JdbcType.VARCHAR),
        @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
        @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
        @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
        @Result(column = "county", property = "county", jdbcType = JdbcType.VARCHAR),
        @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.DATE),
        @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT),
        @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.DATE),
        @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR),
        @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.VARCHAR)})
    School selectByPrimaryKey(Long id);

    @Override
    @UpdateProvider(type = BaseSchoolSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(School record);

    @Override @Update({"update school", "set ", "lat = #{lat,jdbcType=VARCHAR},",
        "lng = #{lng,jdbcType=VARCHAR},", "school_name = #{schoolName,jdbcType=VARCHAR},",
        "phone = #{phone,jdbcType=VARCHAR},", "logo = #{logo,jdbcType=VARCHAR},",
        "address = #{address,jdbcType=VARCHAR},", "province = #{province,jdbcType=VARCHAR},",
        "city = #{city,jdbcType=VARCHAR},", "county = #{county,jdbcType=VARCHAR},",
        "create_by = #{createBy,jdbcType=BIGINT},", "create_date = #{createDate,jdbcType=DATE},",
        "update_by = #{updateBy,jdbcType=BIGINT},", "update_date = #{updateDate,jdbcType=DATE},",
        "remarks = #{remarks,jdbcType=VARCHAR},", "lat = #{lat,jdbcType=VARCHAR}",
        "lng = #{delFlag,jdbcType=VARCHAR}", "del_flag = #{delFlag,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"}) int updateByPrimaryKey(School record);
}